$(function(){
	
	//alert(getCookie("jiaqian"))
	//alert(getCookie("allprice"))
	var cookies =document.cookie
	var cook =cookies.split("; ")
	var arr=[]
	for (var i = 0; i<cook.length ;i++){
			//console.log(cook[i])
			var cookid = cook[i].split("=")
			//console.log(cookid)
			var nameid = cookid[0].split("");
			//.indexOf("n");//
		    if(nameid[0]="n"){
				//console.log(cookid[0]);
				arr.push(cookid[0].substr(1))
				//alert(cookid[0])
			}
	}
	$.ajax({
		type:"get",
		url:"json/xqy.json",
		async:true,
		success:function(data){
			var mag= data.data;
			var str="";
			var ar ='';
			for(var i = 0;i<arr.length;i++){
				var cookie =getCookie(arr[i]);
				for(var j = 0;j<mag.length;j++){
					if(arr[i] == mag[j].id){
						str +='<dl num="'+getCookie("n"+mag[j].id)+'">'
						str +='<dt>'+mag[j].name+'</dt>'
						str +='<dd class="yuanjia">'+mag[j].price+'</dd><dd class="num"></dd>'
						str +='</dl>'
					}
				}
			}
			$("#content .two .goods").append(str)
			$('#content .two .goods dd.num').each(function(){
				//console.log($('#content .two .goods p'));
				$(this).html($(this).parents("dl").attr("num"));
			})
			
			zongjia()
			youhui()
		}
		
	});
	
	function zongjia(){
		
			var spnum= $(".two .goods ul").size()
			//alert(spnum)
			var jiage=0
			var ap =0
			for(var i= 0;i<spnum;i++){
				jiage+= Number($(".yuanjia").eq(i).text())
				//console.log(jiage)
				$(".three .price em").html(jiage)
				if(jiage>200){
					allprice =jiage -15
					$(".three .allprice em").text(ap)
				}else{
					allprice =jiage
					$("#content .jine .li4 strong").text(ap)
					
				}
			  
			}
		}	
		
	function youhui(){
		var price = getCookie("jiaqian");
		var youhui = getCookie("allprice");
		$(".three .price em").html(price);
		$(".allprice em").html(youhui);
	}
})
